package com.baizhi.action;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserAddAllAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        String account = request.getParameter("account");
        String password = request.getParameter("password");
        String question = request.getParameter("question");
        String answer = request.getParameter("answer");
        String sex = request.getParameter("gender");
        String introduce = request.getParameter("introduce");

        UserService us = new UserServiceImpl();
        User user = new User();
        user.setName(name);
        user.setAccount(account);
        user.setPassword(password);
        user.setSex(sex);
        user.setAnswer(answer);
        user.setQuestion(question);
        user.setIntroduce(introduce);
        System.out.println(user);
        us.save(user);


        request.getRequestDispatcher("/login.jsp").forward(request,response);
    }
}
